﻿using ShareHelper;
using ShareHelper.HttpHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace Demo
{
    internal class Program
    {
        private static WinHttpClient HttpClient;
        private static System.Timers.Timer Timer;

        private static void Main(string[] args)
        {

            var data = HexHelper.HexStrToByte("00 40 08 BD 08 A0 08 23 07 AE 08 37 00 76 00 77 00 70 F4 40 04 00 00 00 13 70 13 6B 13 5C 13 6A 13 68 00 00 00 06 04 AD 04 C3 04 A7 04 AF 00 00 00 29 00 00 00 00 01 68 00 80 00 00 DA 65 ");
            var str = new MemoryStream(data);
            var rea = new BinaryReader(str);
            var ccccl = new List<ushort>();
            for (int i = 0; i < data.Length / 2; i++)
            {
                var aaa = rea.ReadBytes(2);
                Array.Reverse(aaa);
                var ccc = BitConverter.ToUInt16(aaa, 0);
                ccccl.Add(ccc);
            }
            Console.WriteLine(string.Join(",", ccccl));
            ;
            ;
            //var aaa = TaskHelper.Run(() => { throw new Exception(""); });
            //var bbb = Task.Run(() => { throw new Exception(""); });

            //Task.WaitAny(aaa);
            //Task.WaitAny(bbb);

            //Console.ReadLine();

            ////单线程访问
            //var http = new WinHttp();
            //var url = "https://www.baidu.com/";
            //http.Open(Method.GET, url);
            //http.UserAgernt = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
            //http.SetRequestHeader("Referer", "https://www.baidu.com/");
            //var data = http.Send();
            //if (data.IsSuccessStatus)//判断是否访问成功
            //{
            //    Console.WriteLine(data.Text);//访问返回内容
            //}
            //else
            //{
            //    Console.WriteLine(data.StatusText);//错误状态
            //}

            ////多线程 同步 Cookie
            //HttpClient = new WinHttpClient
            //{
            //    //访问统一UA
            //    UserAgernt = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
            //};
            //Task.Run(GetBaidu);
            Console.ReadLine();
        }

        public static void GetBaidu()
        {
            //会继承HTTP 客户端的 RequestHeader  和 Cookie 类 达到多线程 访问的效果
            var http = new WinHttp(HttpClient);
            var url = "https://www.baidu.com/";
            http.Open(Method.GET, url);
            var data = http.Send();
            if (data.IsSuccessStatus)//判断是否访问成功
            {
                Console.WriteLine(data.Text);//访问返回内容
            }
            else
            {
                Console.WriteLine(data.StatusText);//错误状态
            }
        }
    }
}